package controller

import (
	"GO/common"
	"GO/model"
	"GO/tools"
	"net/http"

	"github.com/gin-gonic/gin"
)

//修改用户状态
func Modifying_Status(c *gin.Context) {
	//获取用户权限，用来判断是否有能力修改
	class, _ := c.Get("class")
	if !tools.Judge(class) {
		c.JSON(http.StatusOK, gin.H{
			"msg":    "权限不够",
			"status": 400,
		})
		return
	}
	var result model.Modeify
	// 根据请求头中content-type自动推断，绑定PATH参数
	if err := c.ShouldBindJSON(&result); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"error": err.Error()})
		return
	}
	db := common.GetDB()
	if err := db.Exec("UPDATE user_information SET status = ? WHERE id = ?", result.Status, result.Uid); err.Error != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"err": err})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"msg":    "修改成功",
		"status": 200,
	})
}
